package com.ruoyi.web.controller.business;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.business.domain.NumberManagement;
import com.ruoyi.business.service.INumberManagementService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 编号管理Controller
 *
 * @author yangmeng
 * @date 2023-06-01
 */
@RestController
@RequestMapping("/business/number")
public class NumberManagementController extends BaseController {

    @Autowired
    private INumberManagementService numberManagementService;

    /**
     * 查询编号管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:management:list')")
    @GetMapping("/list")
    public TableDataInfo list(NumberManagement numberManagement) {
        startPage();
        List<NumberManagement> list = numberManagementService.selectNumberManagementList(numberManagement);
        return getDataTable(list);
    }

    /**
     * 获取编号管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:management:query')")
    @GetMapping(value = "/{numberId}")
    public AjaxResult getInfo(@PathVariable("numberId") Long numberId) {
        return success(numberManagementService.selectNumberManagementByNumberId(numberId));
    }

    /**
     * 新增编号管理
     */
    @PreAuthorize("@ss.hasPermi('business:management:add')")
    @PostMapping
    public AjaxResult add(@RequestBody NumberManagement numberManagement) {
        if (!numberManagementService.checkNumberNameUnique(numberManagement)) {
            return error("新增'" + numberManagement.getNumberName() + "'失败，编号项目名称已存在");
        }
        return toAjax(numberManagementService.insertNumberManagement(numberManagement));
    }

    /**
     * 修改编号管理
     */
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody NumberManagement numberManagement) {
        if (!numberManagementService.checkNumberNameUnique(numberManagement)) {
            return error("修改'" + numberManagement.getNumberName() + "'失败，编号项目名称已存在");
        }
        return toAjax(numberManagementService.updateNumberManagement(numberManagement));
    }

    /**
     * 删除编号管理
     */
    @PreAuthorize("@ss.hasPermi('business:management:remove')")
    @PostMapping("/delete/{numberIds}")
    public AjaxResult remove(@PathVariable Long[] numberIds) {
        return toAjax(numberManagementService.deleteNumberManagementByNumberIds(numberIds));
    }
}
